defmodule Letcodir.API do
	def pow(x,n,result \\ nil)
	def pow(x,n,result) when result != nil and (is_integer(x) or is_float(x)) and is_integer(n) do
		if n < 0 do
			pow(1/x,-n)
		else
			if n == 0 do
				result
			else
				if Integer.mod(n,2) == 0 do
					Letcodir.API.pow(x * x,Float.floor(n/2) |> Kernel.trunc,result)
				else
					Letcodir.API.pow(x * x,Float.floor(n/2) |> Kernel.trunc,x*result)
				end
			end
		end
	end
	def pow(x,n,_result) when is_integer(n) do
		if Integer.mod(n,2) == 0 do
			pow(x,n,1)
		else
			pow(x,n,x)
		end
	end
end

defmodule Letcodir.API.Node do
	defstruct val: nil, next: nil
end

defmodule Letcodir.API.TreeNode do
	defstruct val: nil, left: nil,right: nil

	def new(val \\ nil,left \\ nil, right \\ nil),do: %Letcodir.API.TreeNode{val: val,left: left,right: right}
	def left(left),do: left.left
	def right(right),do: right.right
	def val(val),do: val.val
end
